function isNull(fieldValue) {
    if (fieldValue == null) {fieldValue=''};
        return (fieldValue.length == 0);
}

function isMatch(field1,field2) {
    if ((field1 != '' && field1 != null) && (field2 != '' && field2 != null))
        return (field1 == field2);
}

function isFieldTooLong(field,valLength){
    if (field != null && field != '')
        return (field.length > valLength);
}

function isFieldTooShort(field,valLength){
    if (field != null && field != '')
        return (field.length < valLength);
}
function setDropDown(v,dd) {
    for (i = 0; i < dd.options.length - 1; i++ ) {
        if ( dd.options[i].value == v ) {
            dd.selectedIndex = i;
            return true
        }
    }
    return false;
}
function isIn(elt, list){
    for(var i=0; i < list.length; i++){
        var tempArray = list[i].split(":")
        if( tempArray[0] == elt ){
            return tempArray;
        }
    }
    return false;
}
function stripCharsInBag (s, bag){
    var i;
    var returnString = "";
    for (i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}
function hasChars(str){
    if(str == null)
        return false;
    str = str.toLowerCase();
    for(var i = 1; i < arguments.length ; i++) {
        arguments[i] = arguments[i].toLowerCase();
        if( str.indexOf( arguments[i] ) != -1 )
            return true;
    }
    return false;
}
function isInteger(s){
    if (s != null && s != ''){
        var re = /^\d+$/;
        return (s.search(re) == -1) ? false : true;
    } else {
        return true;
    }
}
function fillOtherField(field1,field2){
    if (field1 != null && field1.value != '' && (field2.value != null && field2.value == '')){
        field2.value = field1.value;
    }
}

function fnTrimString(pStringToTrim){
    var lsReturnString = pStringToTrim;
    lsReturnString = lsReturnString.replace(/^\s*/, "");
    lsReturnString = lsReturnString.replace(/\s*$/, "");
    return lsReturnString;
}

function fnValidateFromRegEx(pFieldValue, pRegExp, pRequiredField, pAllowSpecialChars){
    var lbValid = false;
    if(pRequiredField){
        if(!isNull(pFieldValue)){
            lbValid =  pRegExp.test(pFieldValue);
            if(!pAllowSpecialChars){
                isRequiredContainsChars(pFieldValue);
            }
        }
    }
    else{
        lbValid =  (isNull(pFieldValue)) ? true : pRegExp.test(pFieldValue);
    }
    return lbValid;
}

function isValidNameField(pFieldValue,pRequiredField){
    var regexp = /^([a-z]| |'|-)+$/i;
    return fnValidateFromRegEx(pFieldValue, regexp, pRequiredField);
}

function isValidAddress(pFieldValue, pRequiredField){
    var regexp = /^([a-z0-9]| |'|-|\.|,|\/)+$/i;
    return fnValidateFromRegEx(pFieldValue, regexp, pRequiredField);
}

function isValidAddress2(pFieldValue, pRequiredField){
     var regexp = /^([a-z0-9]| |'|-|\.|,|#|\/)+$/i;
    return fnValidateFromRegEx(pFieldValue, regexp, pRequiredField);
}

function isValidCity(pFieldValue, pRequiredField){
    var regexp = /^([a-z]| |-|\.|,)+$/i;
    return fnValidateFromRegEx(pFieldValue, regexp, pRequiredField);
}

function isValidDateOfBirth(birthMonthValue,birthDateValue){
	if((birthMonthValue != "" && birthDateValue != "")||(birthMonthValue == "" && birthDateValue == "")){
		return true;
	}
	return false;
}

function isValidUserName(pFieldValue, pRequiredField){
    var lbValid = false;
    if(!isFieldTooShort(pFieldValue, 6)){
        var regexp = /^([a-z0-9]|\+|`|'|@|\.|_|-|)+$/i;
        lbValid = fnValidateFromRegEx(pFieldValue, regexp, pRequiredField, true);
    }
    return lbValid;
}

function isValidPhonePassword(pFieldValue, pRequiredField){
    if(!isNull(pFieldValue)){
        var lbValid = false;
     if(!isFieldTooShort(pFieldValue, 6) && !isFieldTooLong(pFieldValue, 15)){
        lbValid = !/\s/g.test(pFieldValue);
    }
      return lbValid;
  }
   else{
        return true;
  }
}

function isValidPhonePasswordPage(pFieldValue, pRequiredField){
    if(!isNull(pFieldValue)){
        var lbValid = false;
     if(!isFieldTooShort(pFieldValue, 6) && !isFieldTooLong(pFieldValue, 15)){
        lbValid = !/\s/g.test(pFieldValue);
    }
      return lbValid;
  }
   else{
        return false;
  }
}

function isValidPassword(pFieldValue, pRequiredField){
    var regexp = /^(?=.*[a-z|A-Z])(?=.*[0-9])(|!|\@|\#|\$|\%|\^|\&|\*|\"|\(|\))\.*/;
    return fnValidateFromRegEx(pFieldValue, regexp, pRequiredField, true);
}

function isValidChallengeAnswer(pFieldValue, pRequiredField){
    var regexp = /^([a-z0-9]| |)+$/i;
    return fnValidateFromRegEx(pFieldValue, regexp, pRequiredField);
}

function nameContainsNumber(pFieldValue, pRequiredField){
     var regexp = /^[^0-9]+$/i;
     lbValid =  (isNull(pFieldValue)) ? true : regexp.test(pFieldValue);
     return lbValid;
 }

function isRequiredContainsChars(pFieldValue){
    var reIllegalRequiredChars = /\!|\@|\#|\$|\%|\^|\&|\*|\"|\(|\)/;
    if(reIllegalRequiredChars.test(pFieldValue) && webFormVar){
        var lbErrorExists = false;
        for(var i=0; i<webFormVar.errors.length; i++){
            if(webFormVar.errors[i].obj1 == 'specialCharsErrorDiv'){
                lbErrorExists = true;
                break;
            }
        }
        if(!lbErrorExists){
            webFormVar.addError("specialCharsErrorDiv","!inst", "instAlt");
        }
    }
 }

function isValidAccountNumber(pFieldValue){
    var lbValid = false;
    if(!isNull(pFieldValue)){
        var regexp = /^\d+$/;
        if(regexp.test(pFieldValue)){
            if(pFieldValue.length >= 2 && pFieldValue.length <= 9){
                lbValid = true;
            }
        }
    }
    else{
        lbValid = true;
    }
    return lbValid;
}